// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.input;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import org.lwjglx.input.Controller;
import zombie.Lua.LuaEventManager;
import zombie.characters.IsoPlayer;
import zombie.core.BoxedStaticValues;
import zombie.core.Core;
import zombie.core.logger.ExceptionLogger;
import zombie.debug.DebugLog;
import zombie.debug.DebugOptions;
import zombie.iso.Vector2;

public final class JoypadManager {
    public static final JoypadManager instance = new JoypadManager();
    public final JoypadManager.Joypad[] Joypads = new JoypadManager.Joypad[4];
    public final JoypadManager.Joypad[] JoypadsController = new JoypadManager.Joypad[16];
    public final ArrayList<JoypadManager.Joypad> JoypadList = new ArrayList();
    public final HashSet<String> ActiveControllerGUIDs = new HashSet();
    private static final int VERSION_1 = 1;
    private static final int VERSION_2 = 2;
    private static final int VERSION_LATEST = 2;

    public JoypadManager.Joypad addJoypad(int controller, String guid, String name) {
        JoypadManager.Joypad joypad = new JoypadManager.Joypad();
        joypad.ID = controller;
        joypad.guid = guid;
        joypad.name = name;
        this.JoypadsController[controller] = joypad;
        this.doControllerFile(joypad);
        if (!joypad.isDisabled() && this.ActiveControllerGUIDs.contains(guid)) {
            this.JoypadList.add(joypad);
        }

        return joypad;
    }

    private JoypadManager.Joypad checkJoypad(int _int) {
        if (this.JoypadsController[_int] == null) {
            Controller controller = zombie.GameWindow.GameInput.getController(_int);
            this.addJoypad(_int, controller.getGUID(), controller.getGamepadName());
        }

        return this.JoypadsController[_int];
    }

    private void doControllerFile(JoypadManager.Joypad joypad) {
        File file = new File(zombie.ZomboidFileSystem.instance.getCacheDirSub("joypads"));
        if (!file.exists()) {
            file.mkdir();
        }

        file = new File(zombie.ZomboidFileSystem.instance.getCacheDirSub("joypads" + File.separator + joypad.guid + ".config"));

        try {
            FileReader fileReader = new FileReader(file.getAbsolutePath());

            try {
                BufferedReader bufferedReader = new BufferedReader(fileReader);

                try {
                    System.out.println("reloading " + file.getAbsolutePath());
                    int _int = -1;

                    try {
                        String string0 = "";

                        while (string0 != null) {
                            string0 = bufferedReader.readLine();
                            if (string0 != null && string0.trim().length() != 0 && !string0.trim().startsWith("//")) {
                                String[] string1 = string0.split("=");
                                if (string1.length == 2) {
                                    string1[0] = string1[0].trim();
                                    string1[1] = string1[1].trim();
                                    if (string1[0].equals("Version")) {
                                        _int = Integer.parseInt(string1[1]);
                                        if (_int < 1 || _int > 2) {
                                            DebugLog.General.warn("Unknown version %d in %s", _int, file.getAbsolutePath());
                                            break;
                                        }

                                        if (_int == 1) {
                                            DebugLog.General.warn("Obsolete version %d in %s.  Using default values.", _int, file.getAbsolutePath());
                                            break;
                                        }
                                    }

                                    if (_int == -1) {
                                        DebugLog.General.warn("Ignoring %s=%s because Version is missing", string1[0], string1[1]);
                                    } else if (string1[0].equals("MovementAxisX")) {
                                        joypad.MovementAxisX = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("MovementAxisXFlipped")) {
                                        joypad.MovementAxisXFlipped = string1[1].equals("true");
                                    } else if (string1[0].equals("MovementAxisY")) {
                                        joypad.MovementAxisY = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("MovementAxisYFlipped")) {
                                        joypad.MovementAxisYFlipped = string1[1].equals("true");
                                    } else if (string1[0].equals("MovementAxisDeadZone")) {
                                        joypad.MovementAxisDeadZone = Float.parseFloat(string1[1]);
                                    } else if (string1[0].equals("AimingAxisX")) {
                                        joypad.AimingAxisX = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("AimingAxisXFlipped")) {
                                        joypad.AimingAxisXFlipped = string1[1].equals("true");
                                    } else if (string1[0].equals("AimingAxisY")) {
                                        joypad.AimingAxisY = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("AimingAxisYFlipped")) {
                                        joypad.AimingAxisYFlipped = string1[1].equals("true");
                                    } else if (string1[0].equals("AimingAxisDeadZone")) {
                                        joypad.AimingAxisDeadZone = Float.parseFloat(string1[1]);
                                    } else if (string1[0].equals("AButton")) {
                                        joypad.AButton = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("BButton")) {
                                        joypad.BButton = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("XButton")) {
                                        joypad.XButton = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("YButton")) {
                                        joypad.YButton = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("LBumper")) {
                                        joypad.BumperLeft = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("RBumper")) {
                                        joypad.BumperRight = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("L3")) {
                                        joypad.LeftStickButton = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("R3")) {
                                        joypad.RightStickButton = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("Back")) {
                                        joypad.Back = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("Start")) {
                                        joypad.Start = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("DPadUp")) {
                                        joypad.DPadUp = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("DPadDown")) {
                                        joypad.DPadDown = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("DPadLeft")) {
                                        joypad.DPadLeft = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("DPadRight")) {
                                        joypad.DPadRight = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("TriggersFlipped")) {
                                        joypad.TriggersFlipped = string1[1].equals("true");
                                    } else if (string1[0].equals("TriggerLeft")) {
                                        joypad.TriggerLeft = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("TriggerRight")) {
                                        joypad.TriggerRight = Integer.parseInt(string1[1]);
                                    } else if (string1[0].equals("Disabled")) {
                                        joypad.Disabled = string1[1].equals("true");
                                    } else if (string1[0].equals("Sensitivity")) {
                                        joypad.setDeadZone(Float.parseFloat(string1[1]));
                                    }
                                }
                            }
                        }
                    } catch (Exception exception0) {
                        ExceptionLogger.logException(exception0);
                    }
                } catch (Throwable throwable0) {
                    try {
                        bufferedReader.close();
                    } catch (Throwable throwable1) {
                        throwable0.addSuppressed(throwable1);
                    }

                    throw throwable0;
                }

                bufferedReader.close();
            } catch (Throwable throwable2) {
                try {
                    fileReader.close();
                } catch (Throwable throwable3) {
                    throwable2.addSuppressed(throwable3);
                }

                throw throwable2;
            }

            fileReader.close();
        } catch (FileNotFoundException fileNotFoundException) {
            if (!this.ActiveControllerGUIDs.contains(joypad.guid)) {
                this.ActiveControllerGUIDs.add(joypad.guid);

                try {
                    Core.getInstance().saveOptions();
                } catch (Exception exception1) {
                    ExceptionLogger.logException(exception1);
                }
            }
        } catch (IOException iOException) {
            ExceptionLogger.logException(iOException);
        }

        this.saveFile(joypad);
    }

    private void saveFile(JoypadManager.Joypad joypad) {
        File file = new File(zombie.ZomboidFileSystem.instance.getCacheDir() + File.separator + "joypads");
        if (!file.exists()) {
            file.mkdir();
        }

        file = new File(zombie.ZomboidFileSystem.instance.getCacheDirSub("joypads" + File.separator + joypad.guid + ".config"));

        try {
            FileWriter fileWriter = new FileWriter(file.getAbsolutePath());

            try {
                BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

                try {
                    String string = System.getProperty("line.separator");
                    bufferedWriter.write("Version=2" + string);
                    bufferedWriter.write("Name=" + joypad.name + string);
                    bufferedWriter.write("MovementAxisX=" + joypad.MovementAxisX + string);
                    bufferedWriter.write("MovementAxisXFlipped=" + joypad.MovementAxisXFlipped + string);
                    bufferedWriter.write("MovementAxisY=" + joypad.MovementAxisY + string);
                    bufferedWriter.write("MovementAxisYFlipped=" + joypad.MovementAxisYFlipped + string);
                    bufferedWriter.write("// Set the dead zone to the smallest number between 0.0 and 1.0." + string);
                    bufferedWriter.write("// This is to fix \"loose sticks\"." + string);
                    bufferedWriter.write("MovementAxisDeadZone=" + joypad.MovementAxisDeadZone + string);
                    bufferedWriter.write("AimingAxisX=" + joypad.AimingAxisX + string);
                    bufferedWriter.write("AimingAxisXFlipped=" + joypad.AimingAxisXFlipped + string);
                    bufferedWriter.write("AimingAxisY=" + joypad.AimingAxisY + string);
                    bufferedWriter.write("AimingAxisYFlipped=" + joypad.AimingAxisYFlipped + string);
                    bufferedWriter.write("AimingAxisDeadZone=" + joypad.AimingAxisDeadZone + string);
                    bufferedWriter.write("AButton=" + joypad.AButton + string);
                    bufferedWriter.write("BButton=" + joypad.BButton + string);
                    bufferedWriter.write("XButton=" + joypad.XButton + string);
                    bufferedWriter.write("YButton=" + joypad.YButton + string);
                    bufferedWriter.write("LBumper=" + joypad.BumperLeft + string);
                    bufferedWriter.write("RBumper=" + joypad.BumperRight + string);
                    bufferedWriter.write("L3=" + joypad.LeftStickButton + string);
                    bufferedWriter.write("R3=" + joypad.RightStickButton + string);
                    bufferedWriter.write("Back=" + joypad.Back + string);
                    bufferedWriter.write("Start=" + joypad.Start + string);
                    bufferedWriter.write("// Normally the D-pad is treated as a single axis (the POV Hat), and these should be -1." + string);
                    bufferedWriter.write("// If your D-pad is actually 4 separate buttons, set the button numbers here." + string);
                    bufferedWriter.write("DPadUp=" + joypad.DPadUp + string);
                    bufferedWriter.write("DPadDown=" + joypad.DPadDown + string);
                    bufferedWriter.write("DPadLeft=" + joypad.DPadLeft + string);
                    bufferedWriter.write("DPadRight=" + joypad.DPadRight + string);
                    bufferedWriter.write("TriggersFlipped=" + joypad.TriggersFlipped + string);
                    bufferedWriter.write("// If your triggers are buttons, set the button numbers here." + string);
                    bufferedWriter.write("// If these are set to something other than -1, then Triggers= is ignored." + string);
                    bufferedWriter.write("TriggerLeft=" + joypad.TriggerLeft + string);
                    bufferedWriter.write("TriggerRight=" + joypad.TriggerRight + string);
                    bufferedWriter.write("Disabled=" + joypad.Disabled + string);
                    bufferedWriter.write("Sensitivity=" + joypad.getDeadZone(0) + string);
                } catch (Throwable throwable0) {
                    try {
                        bufferedWriter.close();
                    } catch (Throwable throwable1) {
                        throwable0.addSuppressed(throwable1);
                    }

                    throw throwable0;
                }

                bufferedWriter.close();
            } catch (Throwable throwable2) {
                try {
                    fileWriter.close();
                } catch (Throwable throwable3) {
                    throwable2.addSuppressed(throwable3);
                }

                throw throwable2;
            }

            fileWriter.close();
        } catch (IOException iOException) {
            ExceptionLogger.logException(iOException);
        }
    }

    public void reloadControllerFiles() {
        for (int _int = 0; _int < zombie.GameWindow.GameInput.getControllerCount(); _int++) {
            Controller controller = zombie.GameWindow.GameInput.getController(_int);
            if (controller != null) {
                if (this.JoypadsController[_int] == null) {
                    this.addJoypad(_int, controller.getGUID(), controller.getGamepadName());
                } else {
                    this.doControllerFile(this.JoypadsController[_int]);
                }
            }
        }
    }

    public void assignJoypad(int controller, int player) {
        this.checkJoypad(controller);
        this.Joypads[player] = this.JoypadsController[controller];
        this.Joypads[player].player = player;
    }

    public JoypadManager.Joypad getFromPlayer(int player) {
        return this.Joypads[player];
    }

    public JoypadManager.Joypad getFromControllerID(int id) {
        return this.JoypadsController[id];
    }

    public void onPressed(int c, int i) {
        this.checkJoypad(c);
        this.JoypadsController[c].onPressed(i);
    }

    public boolean isDownPressed(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].isDownPressed();
    }

    public boolean isUpPressed(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].isUpPressed();
    }

    public boolean isRightPressed(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].isRightPressed();
    }

    public boolean isLeftPressed(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].isLeftPressed();
    }

    public boolean isLBPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isLBPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isLBPressed();
        }
    }

    public boolean isRBPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isRBPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isRBPressed();
        }
    }

    public boolean isL3Pressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isL3Pressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isL3Pressed();
        }
    }

    public boolean isR3Pressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isR3Pressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isR3Pressed();
        }
    }

    public boolean isRTPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isRTPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isRTPressed();
        }
    }

    public boolean isLTPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isLTPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isLTPressed();
        }
    }

    public boolean isAPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isAPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isAPressed();
        }
    }

    public boolean isBPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isBPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isBPressed();
        }
    }

    public boolean isXPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isXPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isXPressed();
        }
    }

    public boolean isYPressed(int c) {
        if (c < 0) {
            for (int _int = 0; _int < this.JoypadList.size(); _int++) {
                if (((JoypadManager.Joypad)this.JoypadList.get(_int)).isYPressed()) {
                    return true;
                }
            }

            return false;
        } else {
            this.checkJoypad(c);
            return this.JoypadsController[c].isYPressed();
        }
    }

    public boolean isButtonStartPress(int c, int button) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonStartPress(button);
    }

    public boolean isButtonReleasePress(int c, int button) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonReleasePress(button);
    }

    public boolean isAButtonStartPress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return this.isButtonStartPress(c, joypad.getAButton());
    }

    public boolean isBButtonStartPress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonStartPress(joypad.getBButton());
    }

    public boolean isXButtonStartPress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonStartPress(joypad.getXButton());
    }

    public boolean isYButtonStartPress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonStartPress(joypad.getYButton());
    }

    public boolean isAButtonReleasePress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonReleasePress(joypad.getAButton());
    }

    public boolean isBButtonReleasePress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonReleasePress(joypad.getBButton());
    }

    public boolean isXButtonReleasePress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonReleasePress(joypad.getXButton());
    }

    public boolean isYButtonReleasePress(int c) {
        JoypadManager.Joypad joypad = this.checkJoypad(c);
        return joypad.isButtonReleasePress(joypad.getYButton());
    }

    public float getMovementAxisX(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].getMovementAxisX();
    }

    public float getMovementAxisY(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].getMovementAxisY();
    }

    public float getAimingAxisX(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].getAimingAxisX();
    }

    public float getAimingAxisY(int c) {
        this.checkJoypad(c);
        return this.JoypadsController[c].getAimingAxisY();
    }

    public void onPressedAxis(int c, int i) {
        this.checkJoypad(c);
        this.JoypadsController[c].onPressedAxis(i);
    }

    public void onPressedAxisNeg(int c, int i) {
        this.checkJoypad(c);
        this.JoypadsController[c].onPressedAxisNeg(i);
    }

    public void onPressedTrigger(int c, int i) {
        this.checkJoypad(c);
        this.JoypadsController[c].onPressedTrigger(i);
    }

    public void onPressedPov(int c) {
        this.checkJoypad(c);
        this.JoypadsController[c].onPressedPov();
    }

    public float getDeadZone(int c, int axis) {
        this.checkJoypad(c);
        return this.JoypadsController[c].getDeadZone(axis);
    }

    public void setDeadZone(int c, int axis, float value) {
        this.checkJoypad(c);
        this.JoypadsController[c].setDeadZone(axis, value);
    }

    public void saveControllerSettings(int c) {
        this.checkJoypad(c);
        this.saveFile(this.JoypadsController[c]);
    }

    public long getLastActivity(int c) {
        return this.JoypadsController[c] == null ? 0L : this.JoypadsController[c].lastActivity;
    }

    public void setControllerActive(String guid, boolean active) {
        if (active) {
            this.ActiveControllerGUIDs.add(guid);
        } else {
            this.ActiveControllerGUIDs.remove(guid);
        }

        this.syncActiveControllers();
    }

    public void syncActiveControllers() {
        this.JoypadList.clear();

        for (int _int = 0; _int < this.JoypadsController.length; _int++) {
            JoypadManager.Joypad joypad = this.JoypadsController[_int];
            if (joypad != null && !joypad.isDisabled() && this.ActiveControllerGUIDs.contains(joypad.guid)) {
                this.JoypadList.add(joypad);
            }
        }
    }

    public boolean isJoypadConnected(int index) {
        if (index >= 0 && index < 16) {
            assert Thread.currentThread() == zombie.GameWindow.GameThread;

            return zombie.GameWindow.GameInput.getController(index) != null;
        } else {
            return false;
        }
    }

    public void onControllerConnected(Controller controller) {
        JoypadManager.Joypad joypad = this.JoypadsController[controller.getID()];
        if (joypad != null) {
            LuaEventManager.triggerEvent("OnJoypadBeforeReactivate", BoxedStaticValues.toDouble((double)joypad.getID()));
            joypad.bConnected = true;
            LuaEventManager.triggerEvent("OnJoypadReactivate", BoxedStaticValues.toDouble((double)joypad.getID()));
        }
    }

    public void onControllerDisconnected(Controller controller) {
        JoypadManager.Joypad joypad = this.JoypadsController[controller.getID()];
        if (joypad != null) {
            LuaEventManager.triggerEvent("OnJoypadBeforeDeactivate", BoxedStaticValues.toDouble((double)joypad.getID()));
            joypad.bConnected = false;
            LuaEventManager.triggerEvent("OnJoypadDeactivate", BoxedStaticValues.toDouble((double)joypad.getID()));
        }
    }

    public void revertToKeyboardAndMouse() {
        for (int _int = 0; _int < this.JoypadList.size(); _int++) {
            JoypadManager.Joypad joypad = (JoypadManager.Joypad)this.JoypadList.get(_int);
            if (joypad.player == 0) {
                if (zombie.GameWindow.ActivatedJoyPad == joypad) {
                    zombie.GameWindow.ActivatedJoyPad = null;
                }

                IsoPlayer isoPlayer = IsoPlayer.players[0];
                if (isoPlayer != null) {
                    isoPlayer.JoypadBind = -1;
                }

                this.JoypadsController[joypad.getID()] = null;
                this.Joypads[0] = null;
                this.JoypadList.remove(_int);
                break;
            }
        }
    }

    public void renderUI() {
        assert Thread.currentThread() == zombie.GameWindow.GameThread;

        if (DebugOptions.instance.JoypadRenderUI.getValue()) {
            if (!zombie.GameWindow.DrawReloadingLua) {
                LuaEventManager.triggerEvent("OnJoypadRenderUI");
            }
        }
    }

    public void Reset() {
        for (int _int = 0; _int < this.Joypads.length; _int++) {
            this.Joypads[_int] = null;
        }
    }

    public static final class Joypad {
        String guid;
        String name;
        int ID;
        int player = -1;
        int MovementAxisX = 0;
        boolean MovementAxisXFlipped = false;
        int MovementAxisY = 1;
        boolean MovementAxisYFlipped = false;
        float MovementAxisDeadZone = 0.0F;
        int AimingAxisX = 2;
        boolean AimingAxisXFlipped = false;
        int AimingAxisY = 3;
        boolean AimingAxisYFlipped = false;
        float AimingAxisDeadZone = 0.0F;
        int AButton = 0;
        int BButton = 1;
        int XButton = 2;
        int YButton = 3;
        int DPadUp = -1;
        int DPadDown = -1;
        int DPadLeft = -1;
        int DPadRight = -1;
        int BumperLeft = 4;
        int BumperRight = 5;
        int Back = 6;
        int Start = 7;
        int LeftStickButton = 9;
        int RightStickButton = 10;
        boolean TriggersFlipped = false;
        int TriggerLeft = 4;
        int TriggerRight = 5;
        boolean Disabled = false;
        boolean bConnected = true;
        long lastActivity;
        private static final Vector2 tempVec2 = new Vector2();

        public boolean isDownPressed() {
            return this.DPadDown != -1
                ? zombie.GameWindow.GameInput.isButtonPressedD(this.DPadDown, this.ID)
                : zombie.GameWindow.GameInput.isControllerDownD(this.ID);
        }

        public boolean isUpPressed() {
            return this.DPadUp != -1
                ? zombie.GameWindow.GameInput.isButtonPressedD(this.DPadUp, this.ID)
                : zombie.GameWindow.GameInput.isControllerUpD(this.ID);
        }

        public boolean isRightPressed() {
            return this.DPadRight != -1
                ? zombie.GameWindow.GameInput.isButtonPressedD(this.DPadRight, this.ID)
                : zombie.GameWindow.GameInput.isControllerRightD(this.ID);
        }

        public boolean isLeftPressed() {
            return this.DPadLeft != -1
                ? zombie.GameWindow.GameInput.isButtonPressedD(this.DPadLeft, this.ID)
                : zombie.GameWindow.GameInput.isControllerLeftD(this.ID);
        }

        public boolean isLBPressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.BumperLeft, this.ID);
        }

        public boolean isRBPressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.BumperRight, this.ID);
        }

        public boolean isL3Pressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.LeftStickButton, this.ID);
        }

        public boolean isR3Pressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.RightStickButton, this.ID);
        }

        public boolean isRTPressed() {
            int _int = this.TriggerRight;
            if (zombie.GameWindow.GameInput.getAxisCount(this.ID) <= _int) {
                return this.isRBPressed();
            } else {
                return this.TriggersFlipped
                    ? zombie.GameWindow.GameInput.getAxisValue(this.ID, _int) < -0.7F
                    : zombie.GameWindow.GameInput.getAxisValue(this.ID, _int) > 0.7F;
            }
        }

        public boolean isLTPressed() {
            int _int = this.TriggerLeft;
            if (zombie.GameWindow.GameInput.getAxisCount(this.ID) <= _int) {
                return this.isLBPressed();
            } else {
                return this.TriggersFlipped
                    ? zombie.GameWindow.GameInput.getAxisValue(this.ID, _int) < -0.7F
                    : zombie.GameWindow.GameInput.getAxisValue(this.ID, _int) > 0.7F;
            }
        }

        public boolean isAPressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.AButton, this.ID);
        }

        public boolean isBPressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.BButton, this.ID);
        }

        public boolean isXPressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.XButton, this.ID);
        }

        public boolean isYPressed() {
            return zombie.GameWindow.GameInput.isButtonPressedD(this.YButton, this.ID);
        }

        public boolean isButtonPressed(int button) {
            return zombie.GameWindow.GameInput.isButtonPressedD(button, this.ID);
        }

        public boolean wasButtonPressed(int button) {
            return zombie.GameWindow.GameInput.wasButtonPressed(this.ID, button);
        }

        public boolean isButtonStartPress(int button) {
            return zombie.GameWindow.GameInput.isButtonStartPress(this.ID, button);
        }

        public boolean isButtonReleasePress(int button) {
            return zombie.GameWindow.GameInput.isButtonReleasePress(this.ID, button);
        }

        public float getMovementAxisX() {
            if (zombie.GameWindow.GameInput.getAxisCount(this.ID) <= this.MovementAxisX) {
                return 0.0F;
            } else {
                this.MovementAxisDeadZone = zombie.GameWindow.GameInput.getController(this.ID).getDeadZone(this.MovementAxisX);
                float float0 = this.MovementAxisDeadZone;
                if (float0 > 0.0F && float0 < 1.0F) {
                    float float1 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisX);
                    float float2 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisY);
                    Vector2 vector2 = tempVec2.set(float1, float2);
                    if (vector2.getLength() < float0) {
                        vector2.set(0.0F, 0.0F);
                    } else {
                        vector2.setLength((vector2.getLength() - float0) / (1.0F - float0));
                    }

                    return this.MovementAxisXFlipped ? -vector2.getX() : vector2.getX();
                } else {
                    return this.MovementAxisXFlipped
                        ? -zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisX)
                        : zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisX);
                }
            }
        }

        public float getMovementAxisY() {
            if (zombie.GameWindow.GameInput.getAxisCount(this.ID) <= this.MovementAxisY) {
                return 0.0F;
            } else {
                this.MovementAxisDeadZone = zombie.GameWindow.GameInput.getController(this.ID).getDeadZone(this.MovementAxisY);
                float float0 = this.MovementAxisDeadZone;
                if (float0 > 0.0F && float0 < 1.0F) {
                    float float1 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisX);
                    float float2 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisY);
                    Vector2 vector2 = tempVec2.set(float1, float2);
                    if (vector2.getLength() < float0) {
                        vector2.set(0.0F, 0.0F);
                    } else {
                        vector2.setLength((vector2.getLength() - float0) / (1.0F - float0));
                    }

                    return this.MovementAxisYFlipped ? -vector2.getY() : vector2.getY();
                } else {
                    return this.MovementAxisYFlipped
                        ? -zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisY)
                        : zombie.GameWindow.GameInput.getAxisValue(this.ID, this.MovementAxisY);
                }
            }
        }

        public float getAimingAxisX() {
            if (zombie.GameWindow.GameInput.getAxisCount(this.ID) <= this.AimingAxisX) {
                return 0.0F;
            } else {
                this.AimingAxisDeadZone = zombie.GameWindow.GameInput.getController(this.ID).getDeadZone(this.AimingAxisX);
                float float0 = this.AimingAxisDeadZone;
                if (float0 > 0.0F && float0 < 1.0F) {
                    float float1 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisX);
                    float float2 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisY);
                    Vector2 vector2 = tempVec2.set(float1, float2);
                    if (vector2.getLength() < float0) {
                        vector2.set(0.0F, 0.0F);
                    } else {
                        vector2.setLength((vector2.getLength() - float0) / (1.0F - float0));
                    }

                    return this.AimingAxisXFlipped ? -vector2.getX() : vector2.getX();
                } else {
                    return this.AimingAxisXFlipped
                        ? -zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisX)
                        : zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisX);
                }
            }
        }

        public float getAimingAxisY() {
            if (zombie.GameWindow.GameInput.getAxisCount(this.ID) <= this.AimingAxisY) {
                return 0.0F;
            } else {
                this.AimingAxisDeadZone = zombie.GameWindow.GameInput.getController(this.ID).getDeadZone(this.AimingAxisY);
                float float0 = this.AimingAxisDeadZone;
                if (float0 > 0.0F && float0 < 1.0F) {
                    float float1 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisX);
                    float float2 = zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisY);
                    Vector2 vector2 = tempVec2.set(float1, float2);
                    if (vector2.getLength() < float0) {
                        vector2.set(0.0F, 0.0F);
                    } else {
                        vector2.setLength((vector2.getLength() - float0) / (1.0F - float0));
                    }

                    return this.AimingAxisYFlipped ? -vector2.getY() : vector2.getY();
                } else {
                    return this.AimingAxisYFlipped
                        ? -zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisY)
                        : zombie.GameWindow.GameInput.getAxisValue(this.ID, this.AimingAxisY);
                }
            }
        }

        public void onPressed(int i) {
            this.lastActivity = System.currentTimeMillis();
        }

        public void onPressedAxis(int i) {
            this.lastActivity = System.currentTimeMillis();
        }

        public void onPressedAxisNeg(int i) {
            this.lastActivity = System.currentTimeMillis();
        }

        public void onPressedTrigger(int i) {
            this.lastActivity = System.currentTimeMillis();
        }

        public void onPressedPov() {
            this.lastActivity = System.currentTimeMillis();
        }

        public float getDeadZone(int axis) {
            if (axis >= 0 && axis < zombie.GameWindow.GameInput.getAxisCount(this.ID)) {
                float float0 = zombie.GameWindow.GameInput.getController(this.ID).getDeadZone(axis);
                float float1 = 0.0F;
                if ((axis == this.MovementAxisX || axis == this.MovementAxisY) && this.MovementAxisDeadZone > 0.0F && this.MovementAxisDeadZone < 1.0F) {
                    float1 = this.MovementAxisDeadZone;
                }

                if ((axis == this.AimingAxisX || axis == this.AimingAxisY) && this.AimingAxisDeadZone > 0.0F && this.AimingAxisDeadZone < 1.0F) {
                    float1 = this.AimingAxisDeadZone;
                }

                return Math.max(float0, float1);
            } else {
                return 0.0F;
            }
        }

        public void setDeadZone(int axis, float value) {
            if (axis >= 0 && axis < zombie.GameWindow.GameInput.getAxisCount(this.ID)) {
                zombie.GameWindow.GameInput.getController(this.ID).setDeadZone(axis, value);
            }
        }

        public void setDeadZone(float value) {
            for (int _int = 0; _int < zombie.GameWindow.GameInput.getAxisCount(this.ID); _int++) {
                zombie.GameWindow.GameInput.getController(this.ID).setDeadZone(_int, value);
            }
        }

        public int getID() {
            return this.ID;
        }

        public boolean isDisabled() {
            return this.Disabled;
        }

        public int getAButton() {
            return this.AButton;
        }

        public int getBButton() {
            return this.BButton;
        }

        public int getXButton() {
            return this.XButton;
        }

        public int getYButton() {
            return this.YButton;
        }

        public int getLBumper() {
            return this.BumperLeft;
        }

        public int getRBumper() {
            return this.BumperRight;
        }

        public int getL3() {
            return this.LeftStickButton;
        }

        public int getR3() {
            return this.RightStickButton;
        }

        public int getBackButton() {
            return this.Back;
        }

        public int getStartButton() {
            return this.Start;
        }
    }
}
